//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberBlackListDao;
import com.aidong.dao.wills.WorkflowListDao;
import com.aidong.model.wills.MemberBlackList;
import com.aidong.model.wills.WorkflowDetail33;
import com.aidong.model.wills.WorkflowList;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberBlacklist"})
public class MemberBlackListController extends BaseController {
    @Resource
    MemberBlackListDao memberBlackListDao;
    @Resource
    WorkflowListDao workflowListDao;

    public MemberBlackListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("member/blacklist/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        if(!this.chkNull(status)) {
            cd.eq("status", status);
        } else {
            cd.gt("status", Integer.valueOf(0));
        }

        if(!this.chkNull(name)) {
            ConditionMap mv = new ConditionMap(1);
            mv.like("idNumber", "%" + name + "%");
            mv.like("chName", "%" + name + "%");
            mv.like("mobile", "%" + name + "%");
            cd.addSub(mv);
        }

        this.memberBlackListDao.queryPageList(pg, cd, (new OrderSet()).desc("autoId"));
        ModelAndView mv1 = new ModelAndView("member/blacklist/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        MemberBlackList black = new MemberBlackList();
        black.setStatus(Integer.valueOf(0));
        ModelAndView mv = new ModelAndView("member/blacklist/edit");
        mv.addObject("black", black);
        mv.addObject("idType", this.getTypeList("idType"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("black") MemberBlackList black) {
        if(this.chkNull(black.getIdType())) {
            return this.getResult(false, "请选择证件类型");
        } else if(this.chkNull(black.getIdNumber())) {
            return this.getResult(false, "请输入证件号");
        } else {
            if(this.chkNull(black.getStatus())) {
                black.setStatus(Integer.valueOf(0));
            }

            if(this.memberBlackListDao.exists(black.getIdType(), black.getIdNumber())) {
                return this.getResult(false, "证件号已存在");
            } else {
                black.setStatus(Integer.valueOf(2));
                black.setApprove(Integer.valueOf(0));
                black.setCreateUser(this.getLoginUserCode());
                black.setCreateTime(new Date());
                black.setUpdateTime(new Date());

                try {
                    MemberBlackList e = this.memberBlackListDao.getByIdTypeNumber(black.getIdType(), black.getIdNumber());
                    if(e != null) {
                        e.setChName(black.getChName());
                        e.setMobile(black.getMobile());
                        e.setNote(black.getNote());
                        e.setStatus(black.getStatus());
                        e.setApprove(black.getApprove());
                        e.setUpdateTime(new Date());
                        this.memberBlackListDao.update(e);
                    } else {
                        this.memberBlackListDao.add(black);
                    }

                    this.addUserLog("新增黑名单", "序号:" + black.getAutoId() + "," + this.cache.getValue("idType", black.getIdType()) + ":" + black.getIdNumber());
                } catch (Exception var3) {
                    this.log.error("add memberblacklist", var3);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("id") int id) {
        MemberBlackList black = (MemberBlackList)this.memberBlackListDao.getById(Integer.valueOf(id));
        if(black == null) {
            return this.showAlert("没有这个黑名单");
        } else {
            ModelAndView mv = new ModelAndView("member/blacklist/edit");
            mv.addObject("black", black);
            mv.addObject("idType", this.getTypeList("idType"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("black") MemberBlackList black) {
        if(this.chkNullZ(black.getAutoId())) {
            return this.getResult(false, "没有这个黑名单");
        } else {
            if(this.chkNull(black.getStatus())) {
                black.setStatus(Integer.valueOf(0));
            }

            MemberBlackList black1 = (MemberBlackList)this.memberBlackListDao.getById(black.getAutoId());
            if(black1 == null) {
                return this.getResult(false, "没有这个黑名单");
            } else {
                black1.setChName(black.getChName());
                black1.setMobile(black.getMobile());
                black1.setNote(black.getNote());
                black1.setUpdateTime(new Date());

                try {
                    this.memberBlackListDao.update(black1);
                    this.addUserLog("修改黑名单", "序号:" + black.getAutoId() + "," + this.cache.getValue("idType", black.getIdType()) + ":" + black.getIdNumber());
                } catch (Exception var4) {
                    this.log.error("edit memberblacklist", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_chgstat"})
    @ResponseBody
    public String _chgstat(@RequestParam("id") int id, @RequestParam("stat") int stat) {
        MemberBlackList black = (MemberBlackList)this.memberBlackListDao.getById(Integer.valueOf(id));
        if(black == null) {
            return this.getResult(false, "没有这个黑名单");
        } else if(black.getStatus().intValue() == stat) {
            return this.getResult(false, "不用重复操作");
        } else if(stat != 1 && stat != 2) {
            return this.getResult(false, "参数错误");
        } else if(this.workflowListDao.chkWorkflowNotProc33(black.getIdType(), black.getIdNumber())) {
            return this.getResult(false, "这个黑名单正在审批中,不能重复提交!");
        } else {
            try {
                WorkflowList e = new WorkflowList();
                e.setShopCode(this.getLoginShopCode());
                e.setTypeId("33");
                e.setMemberName(black.getChName());
                e.setFileNum(Integer.valueOf(0));
                e.setStatus(Integer.valueOf(0));
                e.setProcResult1(Integer.valueOf(0));
                e.setProcResult2(Integer.valueOf(0));
                e.setProcResult3(Integer.valueOf(0));
                e.setCreateUser(this.getLoginUserCode());
                e.setCreateTime(new Date());
                e.setUpdateTime(new Date());
                WorkflowDetail33 detail = new WorkflowDetail33();
                detail.setIdType(black.getIdType());
                detail.setIdNumber(black.getIdNumber());
                detail.setChName(black.getChName());
                detail.setMobile(black.getMobile());
                detail.setStatus(Integer.valueOf(stat));
                this.workflowListDao.addWorkflow(e, detail);
                this.memberBlackListDao.updateApprove(id, 1);
                this.addUserLog((stat == 1?"添加":"解除") + "黑名单", "序号:" + black.getAutoId() + "," + this.cache.getValue("idType", black.getIdType()) + ":" + black.getIdNumber());
            } catch (Exception var6) {
                this.log.error("edit memberblacklist status", var6);
                return this.getResult(false, "操作发生错误");
            }

            return this.getResult(true, "操作成功,请到审批流-我的申请中提交申请!");
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("id") int id) {
        MemberBlackList black = (MemberBlackList)this.memberBlackListDao.getById(Integer.valueOf(id));
        if(black == null) {
            return this.getResult(false, "没有这个黑名单");
        } else if(black.getStatus().intValue() != 2) {
            return this.getResult(false, "不能删除");
        } else {
            try {
                this.memberBlackListDao.updateStatus(id, 0);
                this.addUserLog("删除黑名单", "序号:" + black.getAutoId() + "," + this.cache.getValue("idType", black.getIdType()) + ":" + black.getIdNumber());
            } catch (Exception var4) {
                this.log.error("del memberblacklist", var4);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
